#include "IntPoint.h"
#include "Containers/Format.h"

bool SIntPoint::operator==(const SIntPoint& Other) const
{
    return X==Other.X&&Y==Other.Y;
}

SVec2 SIntPoint::ToVec2() const
{
    return SVec2(X,Y);
}

SIntPoint SIntPoint::operator+(const SIntPoint &Other) const
{
    return SIntPoint(X+Other.X,Y+Other.Y);
}

SIntPoint& SIntPoint::operator +=(const SIntPoint& Other)
{
    this->X+=Other.X;
    this->Y+=Other.Y;
    return *this;
}

SIntPoint SIntPoint::operator /(const SIntPoint& Other) const
{
    return SIntPoint(X/Other.X,Y/Other.Y);
}

SIntPoint SIntPoint::operator *(const SIntPoint& Other) const
{
    return SIntPoint(X*Other.X,Y*Other.Y);
}

SIntPoint SIntPoint::operator*(const int64_t &Other) const
{
    return SIntPoint(X*Other,Y*Other);
}

SIntPoint SIntPoint::operator -(const SIntPoint& Other) const
{
    return SIntPoint(X-Other.X,Y-Other.Y);
}

SIntPoint SIntPoint::Clamp(const SIntPoint& InValue,const SIntPoint& Min,const SIntPoint& Max )
{
    SIntPoint Ret;
    if(InValue.X < Min.X)
    {
        Ret.X=Min.X;
    }
    else if(InValue.X > Max.X)
    {
        Ret.X=Max.X;
    }else
    {
        Ret.X=InValue.X;
    }

    if(InValue.Y < Min.Y)
    {
        Ret.Y=Min.Y;
    }
    else if(InValue.Y > Max.Y)
    {
        Ret.Y=Max.Y;
    }else
    {
        Ret.Y=InValue.Y;
    }

    return Ret;

}

int64_t SIntPoint::LengthSquare() const
{
    return X*X+Y*Y;
}

SIntPoint Max(const SIntPoint &A, const SIntPoint &B)
{
    return SIntPoint((A.X>B.X?A.X: B.X),(A.Y>B.Y?A.Y: B.Y));
}

SIntPoint Min(const SIntPoint &A, const SIntPoint &B)
{
 return SIntPoint((A.X>B.X?B.X: A.X),(A.Y>B.Y?B.Y: A.Y));
}

CString WH::ToString(const SIntPoint &InValue)
{
    return U"IntPoint(X:"+CString(InValue.X)+U",Y:"+CString(InValue.Y)+U")";
}
